package pl.edu.agh.uddiProxy.parameter;

import pl.edu.agh.uddiProxy.types.AverageCounter;
import pl.edu.agh.uddiProxy.types.ParameterType;
import pl.edu.agh.uddiProxy.types.ParameterValue;

public class AvailabilityAverageCounter implements AverageCounter<Integer> {
	
	public void count(ParameterType parameterType, ParameterValue parameterValue, Integer newValue) {
		parameterValue.setName(parameterType.getName());
		int v;
		if (parameterValue.getValue() == null) {
			v = 0;
		} else {
			v = Integer.parseInt(parameterValue.getValue().toString());
		}
		parameterValue.incrementNumberOfMeasurements();
		long count = parameterValue.getNumberOfMeasurements();
		
		v = (int) ((v * (count - 1) + newValue) / count);
		parameterValue.setValue(Integer.toString(v));
	}


}
